#include <vector>
using namespace std;

typedef unsigned int TIME; // in unit of 0.5 ms
typedef unsigned int RATE; // in unit of bits

enum AppType { VOIP, VIDEO };
enum BlockType { REQUEST, DATA };

#define MAX_BS 5

struct TransportBlock {
  enum Status {
    UActivate, // request generated
    UAir, // request arriving
    UFiber, // request going to BS
    UProcess, // processing request
    DProcess, DSchedule, DFiber, DAir };
  Status status;
  TIME delay;

  enum CodingScheme {
    BPSK, QPSK, QAM16, QAM64 };
  CodingScheme coding;

  unsigned int RBnum;
  bool scheduled;
  //unsigned int Seq;
  //bool lastBlock;

  // timing information
  TIME genTime;
  TIME UScheTime;
  TIME UProcTime;
  TIME DProcTIme;
  TIME DScheTime;
  TIME copyTime;

  /*---------------------------------------------------*/
  TransportBlock(AppType, BlockType);
};

struct Application {
  AppType type;
  TIME duration;
  TIME targetDelay; // how long can this kind of block wait

  void Init(AppType);
};

struct Bearer {
  vector<TransportBlock*> blocks;

  Application application;
  int BSID;
  int userID;

  int bits_sent;
  int bits_received;
  RATE last_rate; //downlink only
  TIME created_time;

  /*---------------------------------------------------*/
  void RequestGen();
  void Proceed();
};

struct BS {
  unsigned int URBCap;
  unsigned int DRBCap;
  TIME delay; // to reach a BS
  bool active;
};

struct RRH {
  BS bs[MAX_BS];
  vector<Bearer*> bearers;

  /*---------------------------------------------------*/
  void Init();
  void UserGen();
  void RequestGen();
  void UplinkSchedule();
  void DownlinkSchedule();
};

